﻿Imports System.Windows.Forms

Public Class MainForm
    Inherits AwesomiumForm

    Private WithEvents rankFix As RankFix

    Public Sub New()
        MyBase.New("UI/R5.htm")
    End Sub

    Protected Overrides Sub InitForm(form As Form)
        With form
            .Text = "R5"
            .Width = 300
            .Height = 400
            .MinimumSize = .Size
        End With
    End Sub

    Protected Overrides Function InvokeLocalMethod(method As String, data As Object, id As String) As Object
        Select Case method
            Case "open"
                Return Me.Open(data)
            Case "start"
                Me.rankFix.Fix(id)
                Return String.Empty
            Case "cancel"
                Me.rankFix.Cancel()
                Return String.Empty
            Case Else
                Return String.Empty
        End Select
    End Function

    Private Function Open(filename As String) As Object
        Dim dialog = New OpenFileDialog()
        dialog.FileName = filename
        If MyBase.ShowDialog(dialog) <> DialogResult.OK Then
            Return String.Empty
        End If

        Me.rankFix = New RankFix(dialog.FileName)

        Return dialog.FileName
    End Function

    Private Sub rankFix_Update(id As String, type As Integer, content As String) Handles rankFix.Update
        MyBase.JobUpdate(id, New With
        {
            .Type = type,
            .content = content
        })
    End Sub
End Class
